package com.study.gank.ui.adapter

import androidx.databinding.ViewDataBinding
import androidx.recyclerview.widget.RecyclerView
import org.jetbrains.anko.sdk27.coroutines.onClick

abstract class BaseBindingAdapter<B : ViewDataBinding> :
    RecyclerView.Adapter<DataBindViewHolder<B>>() {

    // item点击事件
    var mListener: ((pos: Int) -> Unit)? = null

    override fun onBindViewHolder(holder: DataBindViewHolder<B>, position: Int) {
        holder.binding.root.onClick {
            mListener?.invoke(holder.adapterPosition)
        }
    }

    fun setOnItemClickListener(listener: (pos: Int) -> Unit) {
        mListener = listener
    }
}